import request from '@/config/axios'
import type { UserType, User1Type } from './types'

interface RoleParams {
  roleName: string
}

export const loginApi = (data: UserType): Promise<IResponse<UserType>> => {
  // return request.post({ url: '/sys/login', data })
  return request.post({ url: '/user/login', data })
}
export const loginApiI = (data): Promise<LoginResponse<User1Type>> => {
  return request.post({ url: '/sys/login', data })
}
export const loginCodeApi = (data): Promise<LoginResponse<User1Type>> => {
  return request.get({ url: '/sys/randomImage/' + data })
}

export const loginOutApi = (): Promise<IResponse> => {
  return request.get({ url: '/sys/logout' })
}

// 获取user信息
export const getUserInfo = () => {
  return request.get({ url: '/sys/user/getUserInfo' })
}
// 用户账号查询
export const getQueryByUser = (params) => {
  return request.get({ url: '/sys/permission/queryByUser', params })
}
export const getUserListApi = ({ params }: AxiosConfig) => {
  return request.get<{
    total: number
    list: UserType[]
  }>({ url: '/user/list', params })
}

export const getAdminRoleApi = (
  params: RoleParams
): Promise<IResponse<AppCustomRouteRecordRaw[]>> => {
  return request.get({ url: '/role/list', params })
}

export const getTestRoleApi = (params: RoleParams): Promise<IResponse<string[]>> => {
  return request.get({ url: '/role/list', params })
}
